import { Http } from "@/utils/http";

export * from "./teamSalesPerformance";
export * from "./xmateApiCommon.d.ts";
export * from "./teamSalesPerformance.d.ts";
export * from "./xmateApiCommon.d.ts";

const configDefault = {
  headers: {
    "Content-Type": "application/json",
  },
  timeout: 30000,
  baseURL: import.meta.env.VITE_XMATE_BASE_API,
  data: {},
};
// 这里域名变了使用新的
const xmateHttp = new Http(configDefault);

// 我的沟通接口
export const myVisitorAPI = data => {
  return xmateHttp.request({
    url: "/rest/api/customer/meetings",
    method: "POST",
    data,
  });
};

// 获取所有沟通流程
export const getCommunicationFlowsAPI = () => {
  return xmateHttp.request({
    url: "/rest/api/v1/communication/flows",
    method: "GET",
  });
};

// 获取所有沟通环节
// 类型：0 通用流程/客户 1 沟通流程Id 2 商机
export const getCommunicationStagesAPI = ({ type = 0, targetId = "" }) => {
  return xmateHttp.request({
    url: "/rest/api/v1/communication/flows/stages",
    method: "GET",
    params: {
      type,
      targetId,
    },
  });
};

// 获取我的客户列表
export const myCustomerAPI = data => {
  return xmateHttp.request({
    url: "/rest/api/customer/mycustomer/list",
    method: "POST",
    data,
  });
};

// 获取客户标签
export const myCustomerTagsAPI = data => {
  return xmateHttp.request({
    url: "/rest/api/customer/mycustomer/tags",
    method: "POST",
    data,
  });
};

// 团队客户看板
export const teamCustomerListAPI = data => {
  return xmateHttp.request({
    url: "/rest/api/customer/myteam/customer/list",
    method: "POST",
    data,
  });
};

// 团队沟通记录
export const teamVisitListAPI = data => {
  return xmateHttp.request({
    url: "/rest/api/customer/myteam/meetings",
    method: "POST",
    data,
  });
};

// 获取我的组织架构
export const getMydprtAPI = () => {
  return xmateHttp.request({
    url: "/rest/api/contact/v1/org/mymgtdprt",
    method: "GET",
  });
};

// 获取所有组织架构
export const getAllDprtAPI = () => {
  return xmateHttp.request({
    url: "/rest/api/contact/v1/org/dprt",
    method: "GET",
    timeout: 90000,
  });
};

// 绑定客户 到 沟通信息上
export const bindCustomersAPI = data => {
  return xmateHttp.request({
    url: "/rest/api/conference/record/info",
    method: "PUT",
    data,
  });
};

// 上传沟通记录附件
export const uploadVisitFileAPI = data => {
  return xmateHttp.request({
    url: "/rest/api/conference/upload/record",
    method: "POST",
    data,
  });
};

// 删除沟通记录
export const deleteVisitRecordAPI = confId => {
  return xmateHttp.request({
    url: `/rest/api/customer/meetings/${confId}`,
    method: "DELETE",
  });
};

// 获取app版本
export const getAppVersion = () => {
  return xmateHttp.request({
    url: "/rest/product/nova_guide/release/formal/version/android/0.1",
    method: "POST",
  });
};

// 团队看板
// 成员沟通情况统计报告-分页
export const memberBoardAPI = (teamId, periodType = "quarterly", data) => {
  return xmateHttp.request({
    url: `/rest/api/xmate/team/${teamId}/report/${periodType}/users/pager`,
    method: "POST",
    data,
  });
};

// 团队沟通情况统计报告-分页
export const teamBoardAPI = (teamId, periodType = "quarterly", data) => {
  return xmateHttp.request({
    url: `/rest/api/xmate/team/${teamId}/report/${periodType}/sub_teams/pager`,
    method: "POST",
    data,
  });
};

// 获取团队看板总览
export const getTeamBoardOverviewAPI = (teamId, periodType = "quarterly") => {
  return xmateHttp.request({
    url: `/rest/api/xmate/team/${teamId}/report/${periodType}`,
    method: "GET",
  });
};

/*
团队报告列表
pageSize	每页的数量:		false
integer(int32)
pageNumber	当前的页数:		false
integer(int32)
orderBy	排序字段名:		false
string
asc	顺序或倒序:		false
boolean
startTime	开始时间:		false
string(date-time)
endTime	结束时间:		false
string(date-time)
reportType	周期类型:可用值:yearly,weekly,quarterly,monthly
*/
export const teamReportListAPI = data => {
  const { orgId, userId } = data;
  delete data.orgId;
  delete data.userId;
  return xmateHttp.request({
    url: `/rest/api/org/${orgId}/user/${userId}/team/report`,
    method: "POST",
    data,
  });
};

// 团队报告 用户列表
export const teamReportUserListAPI = data => {
  const { teamId, periodType, reportTime } = data;
  return xmateHttp.request({
    url: `/rest/api/xmate/team/${teamId}/report/${periodType}/users/${reportTime}`,
    method: "GET",
  });
};

// 团队报告 团队列表

export const teamReportTeamListAPI = data => {
  const { teamId, periodType, reportTime } = data;
  return xmateHttp.request({
    url: `/rest/api/xmate/team/${teamId}/report/${periodType}/sub_teams/${reportTime}`,
    method: "GET",
  });
};

// 获取商机列表
// TODO: 添加加载更多逻辑
export const opportunityListAPI = (data = {}) => {
  return xmateHttp.request({
    url: `/rest/api/opportunity/list`,
    method: "POST",
    data: {
      pageSize: 999,
      pageNumber: 1,
      ...data,
    },
  });
};

/*
团队报告详情 取得客户列表
pageSize	每页的数量:		false
integer(int32)
pageNumber	当前的页数:		false
integer(int32)
orderBy	排序字段名:		false
string
asc	顺序或倒序:		false
boolean
customerName	客户名称:		false
string
salesName	销售名称:		false
string
startTime	开始时间:		false
string(date-time)
endTime	结束时间:
*/
export const teamReportCustomerListAPI = data => {
  const { orgId, userId } = data;
  delete data.orgId;
  delete data.userId;
  return xmateHttp.request({
    url: `/rest/api/org/${orgId}/user/${userId}/customer`,
    method: "POST",
    data,
  });
};

/*
团队报告详情 客户会议情况
pageSize	每页的数量:		false
integer(int32)
pageNumber	当前的页数:		false
integer(int32)
orderBy	排序字段名:		false
string
asc	顺序或倒序:		false
boolean
customerName	客户名称:		false
string
salesName	销售名称:		false
string
startTime	开始时间:		false
string(date-time)
endTime	结束时间:
*/
export const teamReportDetailConferenceAPI = data => {
  const { orgId, userId, customerId } = data;
  delete data.orgId;
  delete data.userId;
  delete data.customerId;
  return xmateHttp.request({
    url: `/rest/api/org/${orgId}/user/${userId}/customer/${customerId}/meetings`,
    method: "POST",
    data,
    disableProgress: true,
  });
};

// 成员沟通情况统计报告-当前部门
export const teamBoardUsersAPI = (teamId, periodType) => {
  return xmateHttp.request({
    url: `/rest/api/xmate/team/${teamId}/report/${periodType}/users`,
    method: "GET",
  });
};

// 团队沟通情况统计报告-当前直属部门
export const teamBoardSubteamAPI = (teamId, periodType) => {
  return xmateHttp.request({
    url: `/rest/api/xmate/team/${teamId}/report/${periodType}/sub_teams`,
    method: "GET",
  });
};

// 取得团队最近两次报告信息
export const getTeamReportLatest2API = (teamId, periodType, reportTime) => {
  return xmateHttp.request({
    url: `/rest/api/xmate/team/${teamId}/report/${periodType}/${reportTime}/latest2`,
    method: "GET",
  });
};

// 获取人员雷达图
export const getSalesAbilityScoreAPI = (teamId, userId, periodType, type = "ABILITY", topicId) => {
  const data = {};
  if (topicId) {
    data.topicId = topicId;
  }
  return xmateHttp.request({
    url: `/rest/api/org/${teamId}/user/${userId}/assessment/${type}/${periodType}`,
    method: "POST",
    data,
  });
};

// 修复会议
export const fixConferenceAPI = confId => {
  return xmateHttp.request({
    url: `/rest/api/conference/${confId}/record/0/upload`,
    method: "POST",
  });
};


// 获取计划列表
export const getPlanListAPI = (data) => {
  return xmateHttp.request({
    url: `/rest/api/xmate/user/plans`,
    method: "POST",
    data
  });
}

